﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Cesave.Presentation.Permisos.WinForms.Client.ViewModelBase;
using Cesave.Presentation.Permisos.WinForms.Client.Views.Permisos;
using System.Globalization;
using Cesave.Presentation.Permisos.WinForms.Client.Resources;
using Cesave.Application.Permisos.Settings;
using Cesave.Infrastructure.CrossCutting.IoC;
using System.Windows.Forms;

namespace Cesave.Presentation.Permisos.WinForms.Client.ViewModels.Permisos
{
	/// <summary>
	/// 
	/// </summary>
	public partial class ExpedicionViewModel
		: ObservableObject
	{
		#region Private properties

		/// <summary>
		/// 
		/// </summary>
		private ExpedicionView _expedicionView;

		private IPUSSettings _pusSettings;

		#endregion

		#region Constructor

		/// <summary>
		/// 
		/// </summary>
		/// <param name="expedicionView"></param>
		public ExpedicionViewModel(ExpedicionView expedicionView)
		{
			if (expedicionView == null)
				throw new ArgumentNullException("expedicionView");
			_pusSettings = IoCFactory.Resolve<IPUSSettings>();
			_expedicionView = expedicionView;
			WireUpEvents();
			InitModels();
		}

		#endregion

		#region Event methods

		/// <summary>
		/// 
		/// </summary>
		private void WireUpEvents()
		{
			PropertyChanged += ExpedicionViewModel_PropertyChanged;
			_expedicionView.Load += LoadView;
		}

		private void LoadView(object sender, EventArgs e)
		{
			_expedicionView.Text = string.Format(
					CultureInfo.InvariantCulture,
					WindowTitles.ExpedicionWindowTitle
			);
		}

		#endregion

		#region Private methods

		/// <summary>
		/// 
		/// </summary>
		private void InitModels()
		{
			LoadCiclos();
			LoadAreas();
			//LoadUsuarios();
			LoadCultivosNumeros();
			LoadCultivosEstaciones();
			LoadRiegoSistemas();
			LoadRiegoFuentes();
			LoadProduccionTipos();
			LoadFinanciamientos();
		}

		/// <summary>
		/// 
		/// </summary>
		private void StartWaiting()
		{
			_expedicionView.WaitingBar.StartWaiting();
		}

		/// <summary>
		/// 
		/// </summary>
		private void EndWaiting()
		{
			_expedicionView.WaitingBar.EndWaiting();
		}

		/// <summary>
		/// 
		/// </summary>
		/// <param name="message"></param>
		private void ShowMessage(string message)
		{
			MessageBox.Show(_expedicionView,
							message,
							WindowTitles.ExpedicionWindowTitle,
							MessageBoxButtons.OK,
							MessageBoxIcon.Error
						);
		}

		#endregion
	}
}
